package com.dwy2002.product;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dwy2002.common.Result;
import com.dwy2002.common.annotation.RequiresPermission;
import com.dwy2002.enums.Logical;
import com.dwy2002.pojo.dto.product.CategoriesDTO;
import com.dwy2002.pojo.dto.product.CategoriesPageDTO;
import com.dwy2002.pojo.po.product.Categories;
import com.dwy2002.pojo.vo.product.CategoriesVO;
import com.dwy2002.product.service.ICategoriesService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 杜伟毅
 * @version 1.0
 * @since 2025/03/01
 */
@RestController
@RequestMapping("/shopping/categories")
@RequiredArgsConstructor
public class CategoriesController {
    private final ICategoriesService service;

    /**
     * 添加分类
     *
     * @param dto 商品分类信息接收类
     * @author 杜伟毅
     * @since 2025/3/1 0001 15:29
     */
    @RequiresPermission(value = {"A8"}, logical = Logical.OR)
    @PostMapping
    public Result<Void> saveCategories(@RequestBody CategoriesDTO dto) {
        return service.saveCategories(dto);
    }

    /**
     * 修改分类
     *
     * @param dto 商品分类信息接收类
     * @author 杜伟毅
     * @since 2025/3/1 0001 16:20
     */
    @RequiresPermission(value = {"A8"}, logical = Logical.OR)
    @PutMapping
    public Result<Void> updateCategories(@RequestBody CategoriesDTO dto) {
        return service.updateCategories(dto);
    }

    /**
     * 获取分类分页数据
     *
     * @param dto 分类分页前端接受类
     * @author 杜伟毅
     * @since 2025/3/1 0001 22:59
     */
    @RequiresPermission(value = {"A8"}, logical = Logical.OR)
    @PostMapping("/page")
    public Result<Page<Categories>> getCategoriesPage(@RequestBody CategoriesPageDTO dto) {
        return service.getCategoriesPage(dto);
    }

    /**
     * 删除分类
     *
     * @param id 分类id
     * @author 杜伟毅
     * @since 2025/3/2 0002 14:11
     */
    @RequiresPermission(value = {"A8"}, logical = Logical.OR)
    @DeleteMapping("/{id}")
    public Result<Void> deleteCategories(@PathVariable String id) {
        return service.deleteCategories(id);
    }

    /**
     * 获取所有分类名字
     *
     * @author 杜伟毅
     * @since 2025/5/9 0009 13:39
     */
    @RequiresPermission(value = {"A8"}, logical = Logical.OR)
    @GetMapping
    public Result<List<CategoriesVO>> getAllCategoriesName() {
        return service.getAllCategoriesName();
    }

    /**
     * 获取分类详情
     *
     * @param id 分类id
     * @author 杜伟毅
     * @since 2025/5/10 0010 13:35
     */
    @RequiresPermission(value = {"A8"}, logical = Logical.OR)
    @GetMapping("/{id}")
    public Result<Categories> getCategoriesDetails(@PathVariable String id) {
        return service.getCategoriesDetails(id);
    }
}
